<template>
  <div class="m-4">
    <BasicForm @register="register" @submit="handleSubmit" ref="formElRef"/>
  </div>
</template>
<script lang="ts">
  import { defineComponent, ref } from 'vue';
  import { BasicForm,  useForm } from '/@/components/Form/index';

  import { userschemas } from '/@/views/app/demo/user/data';
  //import { CollapseContainer } from '/@/components/Container/index';

  import { useMessage } from '/@/hooks/web/useMessage';
  import { AddUser } from '/@/api/learningcorner/user';
 import { HelloControlModel } from '/@/api/learningcorner/model/HelloControl';

  export default defineComponent({
     components: { BasicForm },
    setup() {
      const { createMessage } = useMessage();
      const formElRef = ref(); //创建一个引用变量
      const [register] = useForm({
        schemas: userschemas,
        labelWidth: 120,
        actionColOptions: {
          span: 30
        },
        submitButtonOptions:{
          text: '添加',
        }
      });
      return {
        register,
        formElRef,
        handleSubmit: async (values: any) => {
          try {
            console.log(values);
            let result: HelloControlModel = await submitAdd(values);
            // const formEl = formElRef.value;
            // formEl.formModel.name = result.name;
            // formEl.formModel.gender = result.gender;
            // formEl.formModel.nation = result.nation;
            // formEl.formModel.birthday = result.birthday;
            // formEl.formModel.id = result.id;
            // formEl.formModel.email = result.email;
            // formEl.formModel.qq = result.qq;
            // formEl.formModel.mobile = result.mobile;
            // formEl.formModel.wechat = result.wechat;
            // formEl.formModel.speciality = result.speciality;
            createMessage.success('提交成功');
          } catch (err) {
            console.log(err);
          }
        },
      };
    },
  });
 function submitAdd(user:any) {
    return AddUser(user);
  }
</script>
